package com.cn.crmsystem.controller.customerController;

import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.customerService.ClueService;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value ="线索数据test",tags ="线索数据接口API")
@Controller
public class ClueController {

    @Autowired
    private ClueService clueService;

    //获取登录的用户pojo对象

    @ResponseBody
    @RequestMapping(value = "/insertClue",method = RequestMethod.POST)
    @ApiOperation(value ="新增线索数据接口",notes = "填写线索基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "customer",value = "线索基本信息",required = false)
    public ResultJson insertClue(@RequestBody Customer clue){
        System.out.println(clue.getName()+"****");
         Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login.getId());
        return  clueService.insertClue(clue,login);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteClue",method = RequestMethod.POST)
    @ApiOperation(value ="删除线索数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "线索数据id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson deleteClue(@RequestParam Integer id){
        System.out.println(id);
        return clueService.deleteClue(id);
    }

    @ResponseBody
    @RequestMapping(value = "/addClueFollow",method = RequestMethod.POST)
    @ApiOperation(value ="新增线索跟进数据接口",notes = "填写线索跟进基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "follow_Up",value = "跟进基本信息",required = false)
    public ResultJson addClueFollow(@RequestBody Follow_Up follow_Up){
        Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login.getId());
        return clueService.addClueFollow(login,follow_Up);
    }

    @ResponseBody
    @RequestMapping(value = "/updateClue",method = RequestMethod.POST)
    @ApiOperation(value ="修改线索数据接口",notes = "填写修改后线索基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "customer",value = "修改后线索基本信息",required = false)
    public ResultJson updateClue(@RequestBody Customer clue) {
        System.out.println(clue.getName() + "****");
        //User user = (User) SecurityUtils.getSubject().getPrincipal();
        return clueService.updateClue(clue);
    }

    @ResponseBody
    @RequestMapping(value = "/updateClueUser",method = RequestMethod.POST)
    @ApiOperation(value ="修改线索负责人数据接口",notes = "传入修改后的负责人id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "修改后的负责人id",required = true,dataType = "Integer",paramType = "query")
    public ResultJson updateClueUser(@RequestParam Integer id) {
        return clueService.updateClueUser(id);
    }

    @ResponseBody
    @RequestMapping(value = "/selectClue",method = RequestMethod.POST)
    @ApiOperation(value ="条件查询线索数据接口",notes = "填写筛选条件数据",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "线索名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "industry",value = "线索（潜在客户）行业",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "level",value = "线索（潜在客户）级别",paramType = "query",dataType = "Integer",required = false),
            @ApiImplicitParam(name = "user_name",value = "负责人名字",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "create_name",value = "创建人名字",paramType = "query",dataType = "String",required = false)
    })
    public ResultJson<List> selectClue(@RequestBody @RequestParam @ApiParam(required = false) Map<String,Object> map) {
        return clueService.selectClue(map);
    }

    @ResponseBody
    @RequestMapping(value = "/updateClueCustomer",method = RequestMethod.POST)
    @ApiOperation(value ="将线索转化为客户数据接口",notes = "传入线索id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "要修改的线索id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson updateClueCustomer(@RequestParam Integer id){
        System.out.println(id);
        return clueService.updateClueCustomer(id);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteAllClue",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除线索数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "线索id",paramType = "query",dataType = "String",required = false)
    public ResultJson deleteAllClue(Integer[] ids){
        System.out.println(ids.length);
        return clueService.deleteAllClue(ids);

    }
}
